<?php
/**
 * wap2.0 购物流程 - 结算
 */

$now = local_time();

$format = array('size'=>'222x280', 'ratio'=>80);

/* 获取 购物车 */
//$cart_info = $mInterface->getShopCartNew($user_token);

#########################

/* 加载json */
include_once( ROOT_PATH . 'includes/cls_json.php');
$json = new JSON;

$_POST['cart'] = htmlspecialchars_decode(urldecode($_POST['cart']));

$_POST['cart'] = $json->decode($_POST['cart'], 1);

$cart = array();
foreach ($_POST['cart'] AS $val){
	$cart[] = $val['product_id'] . ':' . $val['prop'] . ':' . $val['num'];
}

$cart = implode(";", $cart);

$result = $mInterface->comfirmOrder($user_token, $cart);
var_dump($result);
############################

if (empty($cart_info) || !is_array($cart_info))
{
	//show_message('购物袋为空', '返回购物', 'index.html', 'warning');
}


/* 购物袋商品计量 */
$total = $vip_order = array('count'=>0, 'amount'=>0);


/* 新版 购物袋处理 */
foreach ($cart_info['orders_detail'] AS $key => $val)
{
	// 订单 商品处理
	foreach ($val['order_goods'] AS $k => $v)
	{
		// 过滤异常数据
		if (!is_array($v)){
			unset($cart_info['orders_detail'][$key]['order_goods'][$k]);
			continue;
		}

		// 最近添加购物袋的时间
		if ($v['add_time'] > $recently){
			$recently = $v['add_time'];
		}
	}
}



$address_id = wap_getcookie("WAP[address_id]");

/* 获取默认收货地址 , 根据订单收货地址记录持久分仓cookie*/
$consignee = get_one_address($mInterface, $user_token, $address_id);


/* 取得购物袋清空时间 */
$clear_time_notice = '';
$cls_time = cart_clear_time(true);	// 购物袋剩余清空
$clear_time = $cls_time['clear_time'];
if ($clear_time > 0){
	$clear_time_notice = '<span class="fontred">'.floor($clear_time/60).'</span>分<span class="fontred">'.($clear_time%60).'</span>秒';
}


$smarty->assign('clear_time', 			$clear_time);
$smarty->assign('clear_time_formated', 	$clear_time_notice);

$smarty->assign('consignee',			$consignee);
$smarty->assign('payment', 				$payment_list);
$smarty->assign('payment_count', 		count($payment_list));
$smarty->assign('total', 				$total);
$smarty->assign('vip_order', 			$vip_order);
$smarty->assign('cart_info', 			$cart_info);
$smarty->assign('pay_notice', 			$pay_notice);

$smarty->assign('js_total', 			$js_total);

$smarty->assign('cod_money_min', 			COD_MONEY_MIN);
$smarty->assign('cod_money_max', 			COD_MONEY_MAX);


// 返回链接
$show = wap_getcookie("WAP[show]") ? wap_getcookie("WAP[show]") : 2;
$last_addtocart_brand = wap_getcookie("WAP[brd_lst_addtocart]");
if ($last_addtocart_brand)
{
	$smarty->assign('referer', 	'index.php?m=brand&act=index&brand_id='.$last_addtocart_brand.'&cat_id=0&page=1&perpage=10&sort=0&filter_stock=0&show='.$show);
}

$smarty->assign('title', '订单结算');

$smarty->display('flow_checkout.dwt');